/**
 * Copyright (c) 2016- http://github.com/iva0512
 *
 * Licensed under the GPL-3.0
 */
package core.service;

import core.dao.BaseDao;
import core.support.Sort;
import core.support.search.Searchable;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * @author iva0512
 * @version 1.0
 * @date 16-10-27
 * @email iva0512@gmail.com
 * @package core.service
 * @project software
 */
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {RuntimeException.class})
public abstract class BaseServiceImpl<E> implements BaseService<E> {
    protected BaseDao<E> baseDao;

    @Override
    public Serializable save(E entity) {
        return this.baseDao.save(entity);
    }

    @Override
    public void persist(E entity) {
        this.baseDao.persist(entity);
    }

    @Override
    public void delete(E entity) {
        this.baseDao.delete(entity);
    }

    @Override
    public boolean deleteById(Serializable... id) {
        return this.baseDao.deleteById(id);
    }

    @Override
    public void update(E entity) {
        this.baseDao.update(entity);
    }

    @Override
    public void update(Searchable searchable, String[] propName, Object[] propValue) {
        this.baseDao.update(searchable, propName, propValue);
    }

    @Override
    public void update(Searchable searchable, String propName, Object propValue) {
        this.baseDao.update(searchable, propName, propValue);
    }

    @Override
    public E merge(E entity) {
        return this.baseDao.merge(entity);
    }

    @Override
    public void clear() {
        this.baseDao.clear();
    }

    @Override
    public void evict(E entity) {
        this.baseDao.evict(entity);
    }

    @Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
    @Override
    public E get(Serializable id) {
        return this.baseDao.get(id);
    }

    @Override
    public E load(Serializable id) {
        return this.baseDao.load(id);
    }

    @Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
    @Override
    public E get(Searchable searchable) {
        return this.baseDao.get(searchable);
    }

    @Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
    @Override
    public E get(String propName, Object propValue) {
        return this.baseDao.get(propName, propValue);
    }

    @Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
    @Override
    public E get(Map<String, Object> searchParams) {
        return this.baseDao.get(searchParams);
    }

    @Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
    @Override
    public Long countAll() {
        return this.baseDao.countAll();
    }

    @Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
    @Override
    public List<E> findAll(Sort sort, Integer maxResults) {
        return this.baseDao.findAll(sort, maxResults);
    }

    @Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
    @Override
    public List<E> findAll(Integer maxResults) {
        return this.baseDao.findAll(maxResults);
    }

    @Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
    @Override
    public List<E> findAll() {
        return this.baseDao.findAll();
    }

    @Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
    @Override
    public Long count(Searchable searchable) {
        return this.baseDao.count(searchable);
    }

    @Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
    @Override
    public List<E> find(Searchable searchable) {
        return this.baseDao.find(searchable);
    }

    @Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
    @Override
    public List<E> find(Map<String, Object> searchParams) {
        return this.baseDao.find(searchParams);
    }

    @Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
    @Override
    public List<E> find(String propName, Object propValue) {
        return this.baseDao.find(propName, propValue);
    }
}
